﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.HelperMethods;
using NUnit.Framework;

namespace UnitTests.HelperMethodsTests
{
    [TestFixture]
    public class NullHandlingExtensionMethodsFixture
    {
        [Test]
        public void PerformIfNotNullTest1()
        {
            List<object> list1 = null;
            Assert.DoesNotThrow(
                () => list1.PerformIfNotNull(
                    () => list1.Add(new object())));
        }
        [Test]
        public void PerformIfNotNullTest2()
        {
            List<object> list1 = new List<object>();
            object a = new object();
            Assert.DoesNotThrow(
                () => list1.PerformIfNotNull(
                    () => list1.Add(a)));
            Assert.Contains(a, list1, "Action was not performed even though object was not null");
        }

        [Test]
        public void NullSafeEqualsTest1()
        {
            string a = "hello";
            string b = "hello";
            Assert.True(a.NullSafeEquals(b));
        }

        [Test]
        public void NullSafeEqualsTest2()
        {
            string a = null;
            string b = null;
            Assert.True(a.NullSafeEquals(b));
        }

        [Test]
        public void NullSafeEqualsTest3()
        {
            string a = null;
            string b = "hello";
            Assert.False(a.NullSafeEquals(b));
        }

        [Test]
        public void NullSafeEqualsTest4()
        {
            string a = "hello";
            string b = null;
            Assert.False(a.NullSafeEquals(b));
        }

        [Test]
        public void NullSafeEqualsTest5()
        {
            string a = "helo";
            string b = "hello";
            Assert.False(a.NullSafeEquals(b));
        }



    }
}
